{include file="public/header" /}
<body>
<div class="x-body ">
    <form  class="layui-form">
        <div class="layui-form-item">
            <label for="cate_name" class="layui-form-label">分类名称</label>
            <div class="layui-input-inline">
                <input type="text" id="cate_name" name="cate_name" lay-verify="required"   autocomplete="off" class="layui-input" >
                <p id="pLog" style="color:red"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上级分类</label>
            <div class="layui-input-block">
                <select name="pid" lay-verify="required">
                    <option value="0" selected>顶级分类</option>
                    {volist name='cateList' id='vo'}
                    <option value="{$vo.id}"><?php echo str_repeat("-",$vo['level']*3)?>{$vo.cate_name}</option>
                    {/volist}
                </select>

            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <textarea name="cate_keywords" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="cate_description" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">显示导航栏</label>
            <div class="layui-input-block">
                <input type="checkbox"  checked=""  name="show_naw" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>ON</em><i></i></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button class="layui-btn" lay-submit lay-filter="addId">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form'], function(){
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        //监听提交
        form.on('submit(addId)', function(data){
            //console.log(data);
            $.post("{:url('admin/Cate/add')}",data.field,function(info){
                if (info.errorCode===1) {
                    layer.alert("添加成功", {icon: 6},function () {
                        window.parent.location.reload();  //刷新父级页面
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前弹出层
                        parent.layer.close(index);
                    });
                }else{
                    layer.alert(info.msg, {icon: 5});
                }
            },'json');
            return false;
        });
    });
</script>
</body>

</html>